package com.jlzj.factorybean;

import com.jlzj.entity.User;
import com.jlzj.handler.MyInvocationHandler;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;

/**
 * TODO:
 *
 * @author jiangyangchuan
 * @date 2022/8/14 0014 16:28
 */

/**
 * 由于这个类是个工具类，不容的Mapper都要由它来代理，因此我们需要定义一个类类型的属性
 */
public class MyFactoryBean implements FactoryBean {

    private Class targetClass;

    public MyFactoryBean(Class targetClass) {
        this.targetClass = targetClass;
    }

    @Override
    public Object getObject() throws Exception {
        Object proxy = Proxy.newProxyInstance(MyFactoryBean.class.getClassLoader(), new Class[]{targetClass}, new MyInvocationHandler());
        return proxy;
    }

    @Override
    public Class<?> getObjectType() {
        return targetClass;
    }
}
